﻿using System.Collections.Generic;
using UnityEngine;
namespace NodeEditor
{
    /// <summary>
    /// 节点树
    /// </summary>
    [CreateAssetMenu(menuName="创建节点树")]
    public class Tree : ScriptableObject
    {
        public Root root;
        public List<AbstractNode> nodes = new List<AbstractNode>();

        public Tree Clone()
        {
            var tree = new Tree();
            
            for(var i=0;i<nodes.Count;i++)
            {
                var type = nodes[i].GetType();

                var json = LitJson.JsonMapper.ToJson(nodes[i]);
                var node = LitJson.JsonMapper.ToObject(json, type) as AbstractNode;
                tree.nodes.Add( node );

                if(nodes[i] == root)
                {
                    tree.root = node as Root;
                }
            }

            return tree;
        }
    }

}